package com.vrv.common.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.util.Log;

import com.vrv.common.GlobalConstants;
import com.vrv.common.UrlPrefix;

public class CheckNetStatus {
    private static final String TAG = CheckNetStatus.class.getSimpleName();
    private static final boolean DEBUG = true && GlobalConstants.DEBUG;
    
	private static final String STATUS_FILENAME = "status.html";
	public static final String CONTENT = "vrv";
    
	public static Context sContext;
	
	public boolean mWifi = false;
	
    public static void init(Context ctx) {
    	sContext = ctx;
    }
	
    
    /**
     * 检测wifi
     */
	public static boolean detectWifi(){
		if (DEBUG) Log.v(TAG, "detectWifi()");

		boolean bWifi = false;
		
		ConnectivityManager conn = (ConnectivityManager) sContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    	State wifi = conn.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    	if (wifi == State.CONNECTED) {
    		bWifi = true;
		}
    	
    	//模拟器测试返回true
//    	return bWifi;
    	return true;
	}
	
    /**
     * 检测服务器
     */
	public static boolean detectServer(){
    	if (DEBUG) Log.v(TAG, "detectServer()");
    	
    	boolean bServer = false;
    	
    	String prefix = UrlPrefix.getUrlPrefix2();
    	String url = prefix + "/" + STATUS_FILENAME;
		HttpClientToServer httpClientToServer = new HttpClientToServer();
		String response = httpClientToServer.doPost(url, null);
		
		if (DEBUG) Log.v(TAG, "detectServer()...response = " + response);
		
		if (CONTENT.equals(response)) {
			bServer = true;
		} else {
			bServer = false;
		}
		
		return bServer;
    }
    
}
